package com.googlecode.gwtbb.client.only.remote;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Jul 20, 2008
 */
public abstract class EventWrapperCallback<E> implements AsyncCallback<E> {
	private final AsyncCallback real;

	public EventWrapperCallback(AsyncCallback real) {
		this.real = real;
	}

	public abstract boolean isSuccessful(E serverResponse);

	public void onFailure(Throwable caught) {
		real.onFailure(caught);
	}

	public void onSuccess(E result) {
		//noinspection unchecked
		real.onSuccess(result);
		if (isSuccessful(result))
			raiseEvent(result);
	}

	public abstract void raiseEvent(E serverResponse);
}
